package com.pine.app.module.security.oauth.support.client;


import com.pine.app.module.security.core.common.enums.GrantType;
import com.pine.app.module.security.oauth.provider.client.ClientDetails;
import com.pine.app.module.security.oauth.provider.client.ClientDetailsService;
import com.pine.app.module.security.oauth.support.AbstractPreparableIntegrationValidator;
import com.pine.app.module.security.oauth.support.HttpTokenRequest;
import com.pine.app.module.security.oauth.provider.OAuth2Authentication;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xiaoyuan
 * @create 2019/9/29 14:49
 **/

public class ClientCredentialsValidator extends AbstractPreparableIntegrationValidator {

    public ClientCredentialsValidator(){

    }

    public ClientCredentialsValidator(ClientDetailsService clientDetailsService) {
        super(clientDetailsService);
    }

    @Override
    protected OAuth2Authentication checkParam(HttpTokenRequest request) {
        //检查客户端其他信息
        ClientDetails clientDetails =this.checkClientInfo(request);
        return new OAuth2Authentication(coverOauth2Request(clientDetails,request),null);
    }

    @Override
    public HttpTokenRequest createRequest(HttpServletRequest request) {
        return new HttpClientCredentialRequest(request);
    }


    @Override
    public String getGrantType() {
        return GrantType.CLIENT_CREDENTIALS.getName();
    }
}
